import Vue from "vue";
import VueRouter from "vue-router";

import Layout from "@/layout";

import store from "@/store";
import {get} from '@/utils/request'

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "login",
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/Login"),
  },
  // 侧边栏 首页 路由地址
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "home",
        name: "home",
        component: () => import("@/views/Home"),
        meta: {
          title: "首页",
        },
      },

      {
        path: "cgrk",
        name: "Cgrk",
        component: () => import("@/views/medicines/cgrk"),
        meta: {
          title: "采购入库",
        },
      },
      {
        path: "rksh",
        name: "Rksh",
        component: () => import("@/views/medicines/rksh"),
        meta: {
          title: "入库审核",
        },
      },
      {
        path: "kccx",
        name: "Kccx",
        component: () => import("@/views/medicines/kccx"),
        meta: {
          title: "库存查询",
        },
      },
    ],
    //  }
    // {
    //   }
    // ]
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "restoratives",
        name: "restoratives",
        component: () => import("@/views/drug/Restoratives"),
        meta: {
          title: "Restoratives",
        },
      },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "supplier",
        name: "supplier",
        component: () => import("@/views/drug/Supplier"),
        meta: {
          title: "供货商维护",
        },
      },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "prescription",
        name: "prescription",
        component: () => import("@/views/drug/Prescription"),
        meta: {
          title: "处方附加费管理",
        },
      },
    ],
  },
  // {
  //   path: "/",
  //   name: "Layout",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "doctor",
  //       name: "doctor",
  //       component: () => import("@/views/Doctor")
  //     }
  //   ]
  // }
  // 医生管理
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "doctor_manage",
        name: "doctor_manage",
        component: () => import("@/views/DoctorManage"),
        meta: {
          title: "医生管理",
        },
      },
    ],
  },
  // 部门管理
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "dept",
        name: "dept",
        component: () => import("@/views/dept"),
        meta: {
          title: "科室管理",
        },
      },
    ],
  },
  // 挂号费管理
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "registeredfee",
        name: "registeredfee",
        component: () => import("@/views/ghfgl"),
        meta: {
          title: "挂号费管理",
        },
      },
    ],
  },
  // 检查费管理
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "inspectionfee",
        name: "inspectionfee",
        component: () => import("@/views/inspectionfee"),
        meta: {
          title: "检查费管理",
        },
      },
    ],
  },

  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "clinic",
        name: "clinic",
        component: () => import("@/views/drug/Clinic"),
        meta: {
          title: "诊所信息",
        },
      },
    ],
  },
  // 职务管理
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "position",
        name: "position",
        component: () => import("@/views/position"),
        meta: {
          title: "职务管理",
        },
      },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "seedoctor",
        name: "seedoctor",
        component: () => import("@/views/doctor/Seedoctor"),
        meta: {
          title: "新开就诊",
        },
      },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "register",
        name: "register",
        component: () => import("@/views/doctor/Register"),
        meta: {
          title: "门诊挂号",
        },
      },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "registerlist",
        name: "registerlist",
        component: () => import("@/views/doctor/Registerlist"),
        meta: {
          title: "挂号列表",
        },
      },
    ],
  },

  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "doctorscheduling",
        name: "doctorscheduling",
        component: () => import("@/views/doctor/Doctorscheduling"),
        meta: {
          title: "医生排班",
        },
      },
    ],
  },

  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "visitslist",
        name: "visitslist",
        component: () => import("@/views/doctor/Visitslist"),
        meta: {
          title: "就诊列表",
        },
      },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "patient",
        name: "patient",
        component: () => import("@/views/doctor/Patient"),
        meta: {
          title: "患者库",
        },
      },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "zfb",
        name: "zfb",
        component: () => import("@/views/doctor/Zfb"),
        meta: {
          title: "支付宝",
        },
      },
    ],
  },

  //收支统计
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        //收支统计
        path: "szindex",
        name: "szindex",
        component: () => import("@/views/echarts/index"),
        meta: {
          title: "收支统计",
        },
      },
      {
        //检查项目
        path: "inspectionItem",
        name: "inspectionItem",
        component: () => import("@/views/echarts/inspectionItem"),
        meta: {
          title: "检查项目",
        },
      },
      {
        //药品销售统计
        path: "drugStatistics",
        name: "drugStatistics",
        component: () => import("@/views/echarts/DrugStatistics"),
        meta: {
          title: "药品销售统计",
        },
      },
      {
        //年度报表
        path: "statisticalChart",
        name: "statisticalChart",
        component: () => import("@/views/echarts/StatisticalChart"),
        meta: {
          title: "年月报表统计",
        },
       
      },
      {
        //工作量统计
        path: "workloadStatistics",
        name: "workloadStatistics",
        component: () => import("@/views/echarts/WorkloadStatistics"),
        meta: {
          title: "工作量统计",
        }
        },
    ],
  },
  {
    path: "/",
    name: "Layout",
    component: Layout,
    children: [
      {
        path: "403",
        name: "403",
        component: () => import("@/views/error-page/403"),
        meta: {
          title: "无权访问",
        },
      },
    ],
  },
];

const router = new VueRouter({
  routes,
});
// 前置守卫
router.beforeEach((to, from, next) => {
  //如果路由需要跳转
  if (to.path === "/403") {
    let tabs = store.state.tabList;
    tabs.forEach((tab) => {
      if (tab.path === from.path) {
        tabs.splice(tabs.indexOf(tab), 1);
      }
    });
    store.state.tabList = tabs;

  } else {
    // 否则，放行
    next();
  }
  next();
});

// 解决导航重复点击问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

export default router;
